home *** CD-ROM | disk | FTP | other *** search
- ;STHING.ASM - low level interface to Speech Thing SmoothTalker TSR
-
- ;Written 10/90, Kim Kokkonen, TurboPower Software
- ;Copyright (C) 1990, TurboPower Software. All rights reserved.
-
- DATA SEGMENT BYTE PUBLIC
-
- ;Order corresponds to link order given by Pascal declarations
- EXTRN StAllocFromHeap : BYTE ;1 to allocate from heap
- EXTRN SpeechPtr : DWORD ;Entry point for SPEECHVx
- EXTRN lUnknown : WORD ;??
- EXTRN lTone : WORD ;Last values for Tone, etc.
- EXTRN lVolume : WORD
- EXTRN lPitch : WORD
- EXTRN lSpeed : WORD
- EXTRN Int21Err : WORD ;Error value stored by int 21 ISR
- EXTRN Have21 : BYTE ;True when we control int 7E
- EXTRN Have7E : BYTE ;True when we control int 21
- EXTRN Loaded : BYTE ;True if SPEECHVx loaded
- EXTRN SaveSP : WORD ;Keep SPEECHVx from corrupting stack
-
- ;lUnknown may take on values of 0 or 1, but it doesn't seem to make
- ; a difference
-
- DATA ENDS
-
- CODE SEGMENT BYTE PUBLIC
-
- ASSUME CS:CODE, DS:DATA
-
- PUBLIC StInit, StSetParams, StSpeak
- PUBLIC StSetPort, StSetLptPort
- PUBLIC StTextToPhonetic, StPhoneticSpeak
- PUBLIC StInitDict, StInsertDict, StRemoveDict, StDumpDict
- PUBLIC StGrabInt7E, StRestoreInt7E
- PUBLIC StGrabInt21, StRestoreInt21
- PUBLIC StUnload
-
- EXTRN AllocSeg : NEAR ;called in int 21 to allocate memory
-
- ;Convenient equates and macros
- ofst EQU (WORD PTR 0)
- segm EQU (WORD PTR 2)
-
- ;-----------------------------------------------------------------------
- ;Int 21 control
- Old21 DD 0
-
- ;-----------------------------------------------------------------------
- ;procedure New21
- ;
- New21 PROC FAR
- STI ;Allow other interrupts
- CMP AH,48h ;DOS alloc call?
- JZ NewAlloc ;We'll handle it
- CMP AH,49h ;DOS dealloc call?
- JZ NewDealloc ;We'll handle it
- CLI ;Interrupts back off
- JMP CS:Old21 ;Let DOS handle it
- NewAlloc:
- PUSH CX ;Save registers
- PUSH DX
- PUSH SI
- PUSH DI
- PUSH DS
- PUSH ES
- MOV AX,SEG DATA ;Set up Turbo data segment
- MOV DS,AX
- PUSH BX ;Paragraphs to allocate
- CALL AllocSeg ;Let Turbo allocate from heap
- CLC ;Prepare for success
- OR AX,AX ;Success?
- JNZ NewAllocDone ;Jump if so
- MOV AX,8 ;Out of memory error
- MOV Int21Err,AX
- XOR BX,BX ;No memory free
- STC ;Return carry set
- NewAllocDone:
- POP ES
- POP DS
- POP DI
- POP SI
- POP DX
- POP CX
- RET 2
-
- NewDealloc:
- XOR AX,AX ;Return success, but don't do anything
- CLC
- RET 2
- New21 ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StGrabInt21;
- ;
- StGrabInt21 PROC FAR
- CMP Have21,0 ;Do we currently have int 21?
- JNZ Grab21Done ;Jump if so
- MOV AX,3521h
- INT 21h ;Get interrupt 21 vector
- MOV Old21.ofst,BX ;Save it
- MOV Old21.segm,ES
- PUSH DS ;Save DS
- PUSH CS
- POP DS
- MOV DX,OFFSET New21 ;DS:DX -> New21
- MOV AX,2521h
- INT 21h ;Take over int 21
- POP DS
- MOV Have21,1 ;Mark that we have int 21
- Grab21Done:
- RET
- StGrabInt21 ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StRestoreInt21;
- ;
- StRestoreInt21 PROC FAR
- CMP Have21,0 ;Do we currently have int 21?
- JZ Restore21Done ;Jump if not
- PUSH DS ;Save DS
- MOV DX,Old21.ofst
- MOV DS,Old21.segm ;DS:DX -> old int 21
- MOV AX,2521h
- INT 21h ;Restore int 21
- POP DS
- MOV Have21,0
- Restore21Done:
- RET
- StRestoreInt21 ENDP
-
- ;-----------------------------------------------------------------------
- ;Important note: SPEECHVx sometimes trashes the BP and SP registers
- ; the following code carefully saves and restores them
-
- ;-----------------------------------------------------------------------
- ;procedure StInit;
- ;
- StInit PROC FAR
- PUSH BP
- MOV SaveSP,SP
- MOV AL,1 ;function 1
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- RET
- StInit ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StSetParams(Tone, Volume, Pitch, Speed : Word);
- StSetParams PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ SetDone
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- MOV AX,[lUnknown] ;AX=lUnknown
- PUSH AX
- MOV AX,[BP+12] ;AX=Tone
- MOV [lTone],AX
- PUSH AX
- MOV AX,[BP+10] ;AX=Volume
- MOV [lVolume],AX
- PUSH AX
- MOV AX,[BP+8] ;AX=Pitch
- MOV [lPitch],AX
- PUSH AX
- MOV AX,[BP+6] ;AX=Speed
- MOV [lSpeed],AX
- PUSH AX
- MOV AL,2 ;function 2
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- SetDone:
- RET 8
- StSetParams ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StSetPort(Port : Word);
- StSetPort PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ SetPortDone
- MOV BX,SP
- MOV DX,SS:[BX+4] ;DX=Port
- XOR AX,AX
- MOV ES,AX ;ES=0
- OR DX,DX ;0 means default port of LPT1
- JNZ SpecificPort
- MOV DX,ES:[0408h] ;Get port from BIOS LPT1 location
- SpecificPort:
- MOV ES:[4*066h],DX ;Store port in int 66h
- SetPortDone:
- RET 2
- StSetPort ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StSetLptPort(LPTNumber : Byte);
- StSetLptPort PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ SetLptPortDone
- MOV BX,SP
- MOV BL,SS:[BX+4] ;BL=LPTNumber
- OR BL,BL
- JZ SetLptPortDone ;Jump if LPTNumber<1
- CMP BL,3
- JA SetLptPortDone ;Jump if LPTNumber>3
- XOR AX,AX
- MOV ES,AX ;ES=0
- MOV BH,AL
- DEC BX ;BX=0..2
- SHL BX,1 ;Word offset
- ADD BX,408h ;ES:BX -> BIOS port number
- MOV DX,ES:[BX] ;Get port from BIOS location
- MOV ES:[4*066h],DX ;Store port in int 66h
- SetLptPortDone:
- RET 2
- StSetLptPort ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StSpeak(St : string);
- ;
- StSpeak PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ SpeakDone
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- LES DI,[BP+6] ;ES:DI -> St
- PUSH ES
- PUSH DI
- MOV AL,7 ;function 7
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- SpeakDone:
- RET 4
- StSpeak ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StTextToPhonetic(TextSt : string; var PhonSt : string);
- ;
- StTextToPhonetic PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ TextToPhoneticDone
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- LES DI,[BP+10] ;ES:DI -> TextSt
- PUSH ES
- PUSH DI
- LES DI,[BP+6] ;ES:DI -> PhonSt[0]
- PUSH ES
- PUSH DI
- MOV AX,1
- PUSH AX ;PUSH 1
- DEC AX ;function 0
- CALL SpeechPtr ;returns AX?
- MOV SP,SaveSP
- POP BP
- TextToPhoneticDone:
- RET 8
- StTextToPhonetic ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StPhoneticSpeak(St : string);
- ;
- StPhoneticSpeak PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ PhoneticSpeakDone
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- LES DI,[BP+6] ;ES:DI -> St
- PUSH ES
- PUSH DI
- PUSH [lTone] ;could specify alternate speech params
- PUSH [lPitch]
- PUSH [lSpeed]
- PUSH [lVolume]
- MOV AX,[lUnknown]
- ADD AL,8 ;function 8+lUnknown
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- PhoneticSpeakDone:
- RET 4
- StPhoneticSpeak ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StInitDict(Clear : Boolean);
- ;
- StInitDict PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ InitDictDone
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- MOV AL,[BP+6] ;store Clear value
- XOR AH,AH
- PUSH AX
- MOV AL,4 ;function 4
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- InitDictDone:
- RET 2
- StInitDict ENDP
-
- ;-----------------------------------------------------------------------
- ;function StInsertDict(TextSt : string; PhonSt : string) : Boolean;
- ;
- StInsertDict PROC FAR
- XOR AX,AX ;assume False return
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ InsertDictDone
- CMP StAllocFromHeap,0 ;allocating from Turbo heap?
- JZ Insert1 ;jump if not
- CALL StGrabInt21 ;grab int 21 temporarily
- Insert1:
- MOV Int21Err,0 ;clear error indicator
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- LES DI,[BP+10] ;ES:DI -> TextSt
- PUSH ES
- PUSH DI
- LES DI,[BP+6] ;ES:DI -> PhonSt
- PUSH ES
- PUSH DI
- MOV AL,3 ;function 3
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- CALL StRestoreInt21 ;give back int 21 if we have it
- MOV AL,1 ;assume success
- CMP Int21Err,0 ;error in int 21?
- JZ InsertDictDone ;jump if no error
- XOR AL,AL ;return False
- InsertDictDone:
- RET 8
- StInsertDict ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StRemoveDict(TextSt : string);
- ;
- StRemoveDict PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ RemoveDictDone
- CMP StAllocFromHeap,0 ;allocating from Turbo heap?
- JZ Remove1 ;jump if not
- CALL StGrabInt21 ;grab int 21 temporarily
- Remove1:
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- LES DI,[BP+6] ;ES:DI -> TextSt
- PUSH ES
- PUSH DI
- MOV AL,5 ;function 5
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- CALL StRestoreInt21 ;give back int 21 if we have it
- RemoveDictDone:
- RET 4
- StRemoveDict ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StDumpDict(var TextSt : string; var PhonSt : string);
- ;
- StDumpDict PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ DumpDictDone
- PUSH BP
- MOV BP,SP
- MOV SaveSP,BP
- LES DI,[BP+10] ;ES:DI -> TextSt
- PUSH ES
- PUSH DI
- LES DI,[BP+6] ;ES:DI -> PhonSt
- PUSH ES
- PUSH DI
- MOV AL,6 ;function 6
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- DumpDictDone:
- RET 8
- StDumpDict ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StUnload;
- ;
- StUnload PROC FAR
- CMP Loaded,0 ;get out if SPEECHVx not installed
- JZ UnloadDone
- PUSH BP
- MOV SaveSP,SP
- MOV AL,0Bh ;function 0B
- CALL SpeechPtr
- MOV SP,SaveSP
- POP BP
- MOV Loaded,0 ;mark unloaded
- UnloadDone:
- RET
- StUnload ENDP
-
- ;-----------------------------------------------------------------------
- ;Int 7E control
- Old7E DD 0
-
- ;-----------------------------------------------------------------------
- ;Software interrupt used by SPEECHV3 to check for key interrupts
- ;Ok to change AX,DX,ES
- ;Returns AX=0 to continue speech, AX<>0 to halt speech
- ;
- New7E PROC FAR
- XOR AX,AX
- MOV ES,AX
- MOV DL,ES:[041Ah]
- CMP DL,ES:[041Ch] ;Keys in keyboard buffer?
- JZ SpeechContinue ;Jump if not
- MOV AL,0FFh ;Flag stops speech
- SpeechContinue:
- IRET
- New7E ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StGrabInt7E;
- ;
- StGrabInt7E PROC FAR
- CMP Have7E,0 ;Do we currently have int 7E?
- JNZ Grab7EDone ;Jump if so
- MOV AX,357Eh
- INT 21h
- MOV Old7E.ofst,BX
- MOV Old7E.segm,ES
- PUSH DS
- PUSH CS
- POP DS
- MOV DX,OFFSET New7E
- MOV AX,257Eh
- INT 21h
- POP DS
- MOV Have7E,1 ;Mark that we have int 7E
- Grab7EDone:
- RET
- StGrabInt7E ENDP
-
- ;-----------------------------------------------------------------------
- ;procedure StRestoreInt7E;
- ;
- StRestoreInt7E PROC FAR
- CMP Have7E,0 ;Do we currently have int 7E?
- JZ Restore7EDone ;Jump if not
- PUSH DS ;Save DS
- MOV DX,Old7E.ofst
- MOV DS,Old7E.segm ;DS:DX -> old int 7E
- MOV AX,257Eh
- INT 21h ;Restore int 7E
- POP DS
- MOV Have7E,0 ;We no longer have 7E
- Restore7EDone:
- RET
- StRestoreInt7E ENDP
-
- CODE ENDS
- END